package com.nCoV.EpidemicSurveillance.common.utils;

import java.io.IOException;

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;

public class SCPUtils {

    //数据服务器的ip地址
    private static String dataServerIp = "122.51.45.188";
    //数据服务器的用户名
    private static String dataServerUsername = "root";
    //数据服务器的密码
    private static String dataServerPassword = "zht.1314.love";
    //数据服务器的目的文件夹
    private static String dataServerDestDir = "/root/neo4j-community-3.2.6/import";
    
    public static void upload(){
    	//文件scp到数据服务器
    	Connection conn = new Connection(dataServerIp);
    	System.out.println("开始scp文件");
    	try {
    		conn.connect();
    		boolean isAuthenticated = conn.authenticateWithPassword(dataServerUsername, dataServerPassword);
    		if (isAuthenticated == false)
    			throw new IOException("Authentication failed.文件scp到数据服务器时发生异常");
    		SCPClient client = new SCPClient(conn);
    		client.put("D:\\person.csv", dataServerDestDir); //本地文件scp到远程目录
    		client.put("D:\\place.csv", dataServerDestDir); //本地文件scp到远程目录
    		client.put("D:\\relation.csv", dataServerDestDir); //本地文件scp到远程目录
    		conn.close();
    	} catch (IOException e) {
    		e.printStackTrace();
    		System.out.println("文件scp到数据服务器时发生异常");
    	}
    	System.out.println("scp文件结束");
	}
}
